<?php
class SP_Helpers_Query
{
	public static function select()
	{
	}
	
	public static function insert($table,$fields=array())
	{
		$query="INSERT INTO `$table` ";
		foreach($fields as $field=>$value)
		{	
			if(!($value===NULL))
			{
				$f.="`$field`,";
				$v.="'$value',";
			}
		}
		$f=substr($f, 0, -1);
		$v=substr($v, 0, -1);
		$query.="($f) VALUES ($v)";
		return $query;
	}
	
	public static function update($table,$fields=array(),$where=NULL,$limit=NULL)
	{
		$query="UPDATE `$table` SET ";
		foreach($fields as $field=>$value)
		{	
			if(!($value===NULL)) 
			{
				if ($value==='NULL')
				{
					$f.="`$field`=NULL,";
				}
				else
				{
					$f.="`$field`='$value',";
				}
			}
		}
		$f=substr($f, 0, -1);
		$query.=$f;
		if($where)
		{
			$query.=" WHERE ";
			foreach($where as $field=>$value)
			{	
				$w.="`$field`='$value' AND ";
			}
		}
		$w=substr($w, 0, -5);
		$query.=$w;
		if ($limit) $query.=" LIMIT $limit";
		return $query;
	}
	
	public static function delete($table,$where=NULL,$limit=NULL)
	{
		$query="DELETE FROM `$table`";
		if($where)
		{
			$query.=" WHERE ";
			foreach($where as $field=>$value)
			{	
				$w.="`$field`='$value' AND ";
			}
		}
		$w=substr($w, 0, -5);
		$query.=$w;
		if ($limit) $query.=" LIMIT $limit";
		return $query;
	}
	
}
?>